import { Component, OnInit, Input } from '@angular/core';
import { HttpService } from 'src/app/shared/service/http.service';
import { AppGlobalService } from 'src/app/shared/service/app-global.service';
import { PageModalService } from 'src/app/shared/service/page-modal-service';

@Component({
  selector: 'app-invoice-list',
  templateUrl: './invoice-list.component.html',
  styleUrls: ['./invoice-list.component.scss'],
})
export class InvoiceListComponent implements OnInit {
  @Input() tagData: any;
  pageNo = 1;
  constructor(
    private httpService: HttpService,
    private appGlobalService: AppGlobalService,
    private pageModalService: PageModalService,
  ) { }

  ngOnInit() {

  }
  loadMoreData(event) {
    this.pageNo = this.pageNo + 1;
    if (this.tagData.data.data.length >= this.tagData.data.pageTotal) {
      event.target.disabled = true;
      // this.appGlobalService.showToast("没有数据了...", 1000, "middle");
      // event.complete();
      return;
    }
    if (this.tagData.data.submit) {
      if (this.tagData.data.submit.content) {
        this.tagData.data.submit.content.pageNo = this.pageNo;
      }
      this.tagData.data.submit.sessionId = localStorage.getItem("sessionId");
    }

    this.httpService.post(
      "application/submit",
      this.tagData.data.submit,
      res => {
        // 请求数据成功
        if (res.success) {
          const resList = res.data.data;
          this.tagData.data.submit = res.data.submit;
          // 追加返回数据
          if (resList && resList.length > 0) {
            // 追加数据
            resList.map(item => {
              this.tagData.data.data.push(item);
            });
          } else {
            event.target.disabled = true;
          }
        } else {
          // 请求数据失败
          this.appGlobalService.showToast(res.message, 2000, "middle");
        }
        event.target.complete();
      },
      err => {

        // 请求数据失败
        this.appGlobalService.showToast(err.message, 2000, "middle");
        event.target.complete();
      }
    );
  }
  openPage(link) {
    this.pageModalService.openPage(link);
  }
}
